package com.zrc.superframe_aop.utils

import android.view.View
import com.zrc.superframe_aop.annotation.SingleClick

/**
 * @Author: superman
 * @CreateTime: 6/27/21
 * @Descrip: 快速点击工具类
 */
object ClickUtils {

    private var sLastClickTime: Long = 0//最近一次点击的时间

    private var sLastClickViewId = 0//最近一次点击的控件ID

    /**
     * 是否是快速点击
     *
     * @param v 点击的控件
     * @return true:是，false:不是
     */
    fun isFastDoubleClick(v: View) = isFastDoubleClick(v, SingleClick.DEFAULT_INTERVAL_MILLIS)

    /**
     * 是否是快速点击
     *
     * @param v              点击的控件
     * @param intervalMillis 时间间期（毫秒）
     * @return true:是，false:不是
     */
    @JvmStatic
    fun isFastDoubleClick(v: View, intervalMillis: Long): Boolean {
        val time = System.currentTimeMillis()
        val viewId = v.id
        val timeD = time - sLastClickTime
        return if (timeD in 1 until intervalMillis && viewId == sLastClickViewId) {
            true
        } else {
            sLastClickTime = time
            sLastClickViewId = viewId
            false
        }
    }
}